package cn.wolfcode.service.impl;

import cn.wolfcode.domain.MessageBoardDzq;
import cn.wolfcode.mapper.MessageBoardDzqMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IMessageBoardDzqService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageBoardDzqServiceImpl implements IMessageBoardDzqService {

    @Autowired
    private MessageBoardDzqMapper messageBoardDzqMapper;


    @Override
    public void save(MessageBoardDzq messageBoard) {
        Date now = new Date();
        messageBoard.setCreateTimeDzq(now);
        messageBoard.setReplystatusDzq(false);
        messageBoardDzqMapper.insert(messageBoard);
    }

    @Override
    public void delete(Long id) {
        messageBoardDzqMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(MessageBoardDzq messageBoard) {
        messageBoardDzqMapper.updateByPrimaryKey(messageBoard);
    }

    @Override
    public MessageBoardDzq get(Long id) {
        return messageBoardDzqMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MessageBoardDzq> listAll() {
        return messageBoardDzqMapper.selectAll();
    }

    @Override
    public PageInfo<MessageBoardDzq> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<MessageBoardDzq> messageBoards = messageBoardDzqMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<MessageBoardDzq>(messageBoards);
    }
}
